/*
 * Copyright (c) 2017 5utrip.com. All Rights Reserved.
 */
package com.guoyu.project.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.google.common.collect.Maps;
import com.guoyu.project.model.enums.CollegeType;
import org.springframework.stereotype.Service;

import com.guoyu.project.model.School;
import com.guoyu.project.common.constant.Constants;
import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.dao.SchoolDao;

/**
 * 学校,业务类SchoolService
 *
 * @author: xblibo Wed Jun 21 16:01:34 CST 2017
 * @version 1.0.0
 */
@Service
public class SchoolService {

    @Resource
    private SchoolDao schoolDao;

    /**
     * 保存学校数据
     *
     * @param school
     */
    public void saveSchool(School school) {
        schoolDao.save(school);
    }

    /**
     * 更新学校实体
     *
     * @param school
     */
    public void updateSchool(School school) {
        schoolDao.update(school);
    }

    /**
     * 删除学校数据
     *
     * @param schoolId
     */
    public void deleteById(int schoolId) {
        schoolDao.deleteById(schoolId);
    }

    /**
     * 根据id获取学校数据
     *
     * @param schoolId
     * @return
     */
    public School queryById(int schoolId) {
        return schoolDao.queryById(schoolId);
    }

    /**
     * 根据条件分页查询学校数据
     *
     * @param offset
     * @param limit
     * @param params
     * @return
     */
    public Pagination<School> querySchools(int offset, int limit, Map<String, Object> params) {
        // 根据条件获取总记录数
        int total = schoolDao.querySchoolCount(params);

        if (null == params) {
            params = Maps.newHashMap();
        }
        params.put(Pagination.OFFSET, offset);
        params.put(Pagination.LIMIT, limit);
        // 分页查询数据
        List<School> schoolList = schoolDao.querySchools(params);

        return new Pagination(offset, limit, total, schoolList);
    }

    public List<School> queryAll() {
        Map<String, Object> params = Maps.newHashMap();
        return schoolDao.querySchools(params);
    }

    public List<School> queryByProvince(int provinceId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("provinceId", provinceId);
        return schoolDao.querySchools(params);
    }

    public List<School> queryByType(CollegeType collegeType) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("category", collegeType);
        return schoolDao.querySchools(params);
    }

}